
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>创建Feature · GeoTools使用文档</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="shengshi_feiyang@yeah.net">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-cuav-chapters/cuav-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-multipart/multipart.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-fexa/fexa.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="geometry.html" />
    
    
    <link rel="prev" href="created.html" />
    

    </head>
    <body>
        
<div class="book">
	<div class="header-inner">
		<!-- LOGO -->
		<div class="logo"></div>
		<span class="title"></span>

		<!-- Search -->
		
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>


		<!-- Nav -->
		<ul class="header-nav">
			<li>
				<a href="https://geotools.org/" target="_blank">官网文档</a>
			</li>
		</ul>
	</div>

	<div class="book-summary">
		<div class="book-summary-title">文档目录</div>
		
		
		<nav role="navigation">
			


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../ogc/">
            
                <a href="../ogc/">
            
                    
                    OGC基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../ogc/opengis.html">
            
                <a href="../ogc/opengis.html">
            
                    
                    opengis简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../ogc/wms.html">
            
                <a href="../ogc/wms.html">
            
                    
                    wms服务简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../ogc/wfs.html">
            
                <a href="../ogc/wfs.html">
            
                    
                    wfs服务简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../ogc/wcs.html">
            
                <a href="../ogc/wcs.html">
            
                    
                    wcs服务简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../ogc/wmts.html">
            
                <a href="../ogc/wmts.html">
            
                    
                    WMTS服务简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../ogc/front.html">
            
                <a href="../ogc/front.html">
            
                    
                    前端显示组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="./">
            
                <a href="./">
            
                    
                    GeoTools基本使用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="standards-covered.html">
            
                <a href="standards-covered.html">
            
                    
                    涵盖的标准
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="created.html">
            
                <a href="created.html">
            
                    
                    创建GeoTools
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.3" data-path="feature.html">
            
                <a href="feature.html">
            
                    
                    创建Feature
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="geometry.html">
            
                <a href="geometry.html">
            
                    
                    JTS-geometry
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="de-9im.html">
            
                <a href="de-9im.html">
            
                    
                    DE-9IM模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="geometry-operator.html">
            
                <a href="geometry-operator.html">
            
                    
                    geometry操作
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../app-integration/">
            
                <a href="../app-integration/">
            
                    
                    GeoTools与应用集成
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


		</nav>
		
		
	</div>

	<!-- Content nav -->
	<div class="book-anchor">
		<div class="book-anchor-title">在这篇文章中:</div>
		<div class="book-anchor-body">

		</div>
	</div>

	<div class="book-body">
		
		<div class="body-inner">
			
			

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >创建Feature</a>
    </h1>
</div>




			<div class="page-wrapper" tabindex="-1" role="main">
				<div class="page-inner">
					
<div id="book-search-results">
    <div class="search-noresults">
    
					<section class="normal markdown-section">
						
						<h1 id="feature&#x5B9A;&#x4E49;">Feature&#x5B9A;&#x4E49;</h1>
<p>A feature is something that can be drawn on a map. The strict definition is that a feature is something in the real world &#x2013; a feature of the landscape - Mt Everest, the Eiffel Tower(&#x7279;&#x5F81;&#x662F;&#x53EF;&#x4EE5;&#x753B;&#x5728;&#x5730;&#x56FE;&#x4E0A;&#x7684;&#x4E1C;&#x897F;&#x3002;&#x4E25;&#x683C;&#x7684;&#x5B9A;&#x4E49;&#x662F;&#xFF0C;&#x7279;&#x5F81;&#x662F;&#x73B0;&#x5B9E;&#x4E16;&#x754C;&#x4E2D;&#x7684;&#x4E00;&#x4E9B;&#x4E1C;&#x897F;&#x2014;&#x2014;&#x98CE;&#x666F;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x7279;&#x5F81;&#x2014;&#x2014;&#x73E0;&#x7A46;&#x6717;&#x739B;&#x5CF0;&#x3001;&#x57C3;&#x83F2;&#x5C14;&#x94C1;&#x5854;)</p>
<h2 id="java&#x4E0E;geospatial&#x5BF9;&#x7167;&#x5173;&#x7CFB;">java&#x4E0E;geospatial&#x5BF9;&#x7167;&#x5173;&#x7CFB;</h2>
<table>
<thead>
<tr>
<th style="text-align:left">Java</th>
<th style="text-align:left">Geospatial</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><code>Object</code></td>
<td style="text-align:left"><code>Feature</code></td>
</tr>
<tr>
<td style="text-align:left"><code>Class</code></td>
<td style="text-align:left"><code>FeatureType</code></td>
</tr>
<tr>
<td style="text-align:left"><code>Field</code></td>
<td style="text-align:left"><code>Attribute</code></td>
</tr>
<tr>
<td style="text-align:left"><code>Method</code></td>
<td style="text-align:left"><code>Operation</code></td>
</tr>
</tbody>
</table>
<h2 id="featureclass">FeatureClass</h2>
<p><img src="../assets/feature.png" alt="feature&#x7C7B;UML"></p>
<h2 id="geometry">Geometry</h2>
<p>The other difference between an Object and a Feature is that a Feature has some form of location information (if not we would not be able to draw it on a map). The location information is going to be captured by a Geometry (or shape) that is stored in an attribute.</p>
<p><img src="../assets/geometry.png" alt="geometry&#x56FE;&#x7247;"></p>
<p>We make use of the JTS Topology Suite (JTS) to represent <code>Geometry</code>. The JTS library provides an excellent implementation of <code>Geometry</code> &#x2013; and gets geeky points for having a recursive acronym! JTS is an amazing library and does all the hard graph theory to let you work with geometry in a productive fashion.</p>
<p>Here is an example of creating a <code>Point</code> using the Well-Known-Text (WKT) format.</p>
<pre><code>GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );

WKTReader reader = new WKTReader( geometryFactory );
Point point = (Point) reader.read(&quot;POINT (1 1)&quot;);
</code></pre><p>You can also create a <code>Point</code> by hand using the <code>GeometryFactory</code> directly.</p>
<pre><code>GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );

Coordinate coord = new Coordinate( 1, 1 );
Point point = geometryFactory.createPoint( coord );
</code></pre><h2 id="datastore">DataStore</h2>
<p>The DataStore API is used to represent a File, Database or Service that has spatial data in it. The API has a couple of moving parts as shown below.</p>
<p><img src="../assets/datastore.png" alt=""></p>
<p>The <code>FeatureSource</code> is used to read features, the sub-class <code>FeatureStore</code> is used for read/write access.</p>
<p>The way to tell if a <code>File</code> can be written to in GeoTools is to use an <code>instanceof</code> check.</p>
<pre><code>String typeNames = dataStore.getTypeNames()[0];
SimpleFeatureSource source = store.getfeatureSource( typeName );
if( source instanceof SimpleFeatureStore){
   SimpleFeatureStore store = (SimpleFeatureStore) source; // write access!
   store.addFeatures( featureCollection );
   store.removeFeatures( filter ); // filter is like SQL WHERE
   store.modifyFeature( attribute, value, filter );
}
</code></pre>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
						
					</section>
					
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

				</div>
			</div>
			
		</div>

		
		
		<a href="created.html" class="navigation navigation-prev " aria-label="Previous page: 创建GeoTools">
			<i class="fa fa-angle-left"></i>
		</a>
		
		
		<a href="geometry.html" class="navigation navigation-next " aria-label="Next page: JTS-geometry">
			<i class="fa fa-angle-right"></i>
		</a>
		
		
		
	</div>
	<script>
		var gitbook = gitbook || [];
		gitbook.push(function() {
			gitbook.page.hasChanged({"page":{"title":"创建Feature","level":"1.3.3","depth":2,"next":{"title":"JTS-geometry","level":"1.3.4","depth":2,"path":"use-guider/geometry.md","ref":"use-guider/geometry.md","articles":[]},"previous":{"title":"创建GeoTools","level":"1.3.2","depth":2,"path":"use-guider/created.md","ref":"use-guider/created.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-sharing","-fontsettings","back-to-top-button","copy-code-button","cuav-chapters","heading-anchors","theme-fexa","popup","splitter","multipart@0.3.0"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"splitter":{},"search":{},"cuav-chapters":{"summaryMaxSize":20,"useLimitExpanded":false},"popup":{},"multipart":{},"theme-fexa":{"search-placeholder":"输入关键字搜索","logo":"./logo.png","favicon":"./favicon.ico"},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"heading-anchors":{},"highlight":{},"back-to-top-button":{},"copy-code-button":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"shengshi_feiyang@yeah.net","pdf":{"pageNumbers":true,"fontSize":18,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":30,"left":30,"top":30,"bottom":50}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"themeFexa":{"nav":[{"url":"https://geotools.org/","target":"_blank","name":"官网文档"}]}},"title":"GeoTools使用文档","gitbook":"*"},"file":{"path":"use-guider/feature.md","mtime":"2020-12-07T08:52:14.167Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-12-31T07:07:14.395Z"},"basePath":"..","book":{"language":""}});
		});
	</script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-cuav-chapters/cuav-chapters.js"></script>
        
    
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/1.2.1/anchor.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-heading-anchors/anchor-style.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-fexa/fexa.js"></script>
        
    

    </body>
</html>

